package com.azt.api.dto.shop;


import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

/**
 * 产品搜索条件
 * Created by 张栋 on 2017/2/8 13:37
 */
public class ProSearchParam {

    private Integer companyId;//公司id
    private String keywords;//目前仅代表产品名称
    private String priceStart;//价格起始(>=)
    private String priceEnd;//价格截至(<=)
    private String categoryIds;//类目id,查该类目下的产品,多个","号分割,但要保证多个类别是同一层级的
    private String provinceCode;//省code,
    private String cityCode;//市code,
    private Integer orderType = 0;//0默认,创建时间desc,1价格asc,2价格desc,3销量asc,4销量desc,5浏览量asc,6浏览量desc


    private Integer pageNo = 1;
    private Integer pageSize = 10;

    public String getKeywords() {
        if (keywords != null) {
            keywords = keywords.trim();
        }
        return keywords;
    }

    public void setKeywords(String keywords) {
        this.keywords = keywords;
    }

    public String getPriceStart() {
        return priceStart;
    }

    /**
     * 价格不合理时,自动纠正
     * Created by 张栋 on 2017/2/16 14:47
     */
    public void priceAI() {

        if (StringUtils.isNotBlank(priceStart) && StringUtils.isNotBlank(priceEnd)) {
            if (new BigDecimal(priceStart).compareTo(new BigDecimal(priceEnd)) == 1) {
                String temp = priceStart;
                setPriceStart(getPriceEnd());
                setPriceEnd(temp);
            }
        }
    }

    public void setPriceStart(String priceStart) {
        this.priceStart = priceStart;
    }

    public String getPriceEnd() {
        return priceEnd;
    }

    public void setPriceEnd(String priceEnd) {
        this.priceEnd = priceEnd;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public String getCategoryIds() {
        return categoryIds;
    }

    public void setCategoryIds(String categoryIds) {
        this.categoryIds = categoryIds;
    }

    public Integer getOrderType() {
        return orderType;
    }

    public void setOrderType(Integer orderType) {
        this.orderType = orderType;
    }

    public Integer getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Integer companyId) {
        this.companyId = companyId;
    }

    public String getProvinceCode() {
        return provinceCode;
    }

    public void setProvinceCode(String provinceCode) {
        this.provinceCode = provinceCode;
    }

    public String getCityCode() {
        return cityCode;
    }

    public void setCityCode(String cityCode) {
        this.cityCode = cityCode;
    }

    public List<String> getCategoryList(){
        String categoryIds = getCategoryIds();
        if(StringUtils.isNotBlank(categoryIds)){
            String[] split = categoryIds.split(",");
            return Arrays.asList(split);
        }else{
            return null;
        }
    }
}
